﻿#region Summary

// 
// Owner : JackieHan 
// 
// Solution : Erp 
// 
// Project : Jackie.Utility.BvConversion
// 
// File : DefaulteConversionConfig.cs
// 
// CopyRight : Copyright © 2010-2011 Skomart Corporation, All Rights Reserved 
// 
// Summary : 默认的转换配置
// 
// History : 
//			2012-07-13 14:44:37	    Create 
// 

#endregion

#region Using

using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Xml;

#endregion

namespace Jackie.Utility.BvConversion
{
    ///<summary>
    ///默认的转换配置
    ///</summary>
    public class DefaulteConversionConfig:IConversionConfig
    {
        #region Implementation of IConversionConfig

        public BusinessViewConfigCollection Config()
        {
            string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
                                                 ConfigurationManager.AppSettings["conversionConfigFilePath"]);

            if (!File.Exists(configFilePath))
                throw new FileNotFoundException(string.Format("the config file [path:{0}] is not found", configFilePath));

            var businessObjectConfig = new BusinessViewConfigCollection();

            XmlDocument doc = new XmlDocument();
            doc.Load(configFilePath);

            XmlNodeList objectConversionNodes = doc.GetElementsByTagName("Conversion");
            foreach (XmlNode configNode in objectConversionNodes)
            {
                ObjectConversionConfig config = new ObjectConversionConfig(configNode);
                if (!businessObjectConfig.ContainsKey(config.BusinessType))
                {
                    businessObjectConfig[config.BusinessType] = new Dictionary<string, ObjectConversionConfig>();
                }
                businessObjectConfig[config.BusinessType][config.ViewType] = config;
            }
            return businessObjectConfig;
        }

        #endregion
    }
}